package com.lq.leetcode;

import java.util.Stack;

/**
 * Main739
 *
 * @author qingqing
 * @date 2025/3/4
 */

public class Main739 {
    public int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> stack = new Stack<>();
        int length = temperatures.length;
        int[] res = new int[length];
        for (int i = 0; i < temperatures.length; i++) {
            while (stack.size() != 0 && temperatures[stack.peek()] < temperatures[i]) {
                Integer top = stack.pop();
                res[top] = i - top;
            }
            stack.push(i);

        }
        return res;
    }
}
